package com.mitdy.sg.common.bean;

import java.util.Map;
import java.util.Map.Entry;

/**
 * easyui的datagrid向后台传递参数使用的model
 * 
 * @author zh
 * 
 */
public class Pagination implements java.io.Serializable {

    private static final long serialVersionUID = -4652918180001959791L;

    private int page = 1; // 当前页
    private int rows = 1000; // 每页显示记录数
    private String orderBy; // 排序

    private Map<String, String> sorters;

    public Pagination() {
    }

    public Pagination(int page, int rows) {
        this.page = page;
        this.rows = rows;
    }

    private void setOrderBy(Map<String, String> sorters) {
        if (sorters != null && !sorters.isEmpty()) {
            StringBuffer buffer = new StringBuffer();
            int i = 0;
            for (Entry<String, String> entry : sorters.entrySet()) {
                buffer.append(" ").append(entry.getKey()).append(" ").append(entry.getValue());

                if (i < sorters.size() - 1) {
                    buffer.append(",");
                }

                i++;
            }

            orderBy = buffer.toString();
        }
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public Map<String, String> getSorters() {
        return sorters;
    }

    public void setSorters(Map<String, String> sorters) {
        this.sorters = sorters;
        setOrderBy(sorters);
    }

}
